package com.aizuda.boot.modules.business.contract_operation_log.controller;

import com.aizuda.boot.modules.common.constant.enums.ResponseCodeEnum;
import com.aizuda.boot.modules.business.contract_operation_log.domain.vo.ContractOperationLogRespDTO;
import com.aizuda.boot.modules.business.contract_operation_log.service.ContractOperationLogService;
import com.aizuda.boot.modules.business.contract.dto.SingleResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;

import jakarta.annotation.Resource;
import java.util.List;

/**
 * 合同操作日志Controller
 */
@Slf4j
@RestController
@RequestMapping("/contract-operation-log")
@Tag(name = "合同操作日志", description = "合同操作日志相关接口")
public class ContractOperationLogController {

    @Resource
    private ContractOperationLogService contractOperationLogService;

    /**
     * 获取协商日志
     * @param contractId 合同ID
     * @param flowType 流程类型
     * @return 协商日志列表
     */
    @Operation(summary = "获取协商日志")
    @GetMapping("/{contractId}")
    public SingleResponse<List<ContractOperationLogRespDTO>> getNegotiationLogs(
            @Parameter(description = "合同ID", required = true) @PathVariable Integer contractId,
            @Parameter(description = "流程类型", required = true) @RequestParam String flowType) {
        
        try {
            List<ContractOperationLogRespDTO> logs = contractOperationLogService.getNegotiationLogs(contractId, flowType);
            return SingleResponse.of(logs);
        } catch (Exception e) {
            log.error("获取协商日志失败，合同ID: {}, 流程类型: {}", contractId, flowType, e);
            return SingleResponse.failure(ResponseCodeEnum.SHOW_MSG.getCode(), "获取协商日志失败: " + e.getMessage());
        }
    }
} 